// 角色管理接口
import request from '@/utils/request'
import type { RoleResData,queryParams } from './roleType'

enum API {
  all_role = '/api/role/page',
  add_role = '/api/role/add',
  update_role = '/api/role/update',
  delete_role = '/api/role/delete',
  getMenuByRoleid = '/api/menu/role-menus',
  getMenuByUserName = '/api/menu/user-menus',
}
// 获取角色列表
export const reqAllRole = (params: queryParams) => {
  const queryParams = new URLSearchParams({
    current: params.current.toString(),
    size: params.size.toString(),
    name: params.name || '',
    active: params.active
  }).toString()
  const url = `${API.all_role}?${queryParams}`
  return request.get<any, RoleResData>(url)
}
// 新增角色、编辑角色
export const reqAddOrUpdateRole = (data: any) => {
  if (data.id) {
    return request.put<any,any>(API.update_role, data)
  } else {
    return request.post<any,any>(API.add_role, data)
  }
}
// 删除单个角色
export const reqRemoveRole = (id: number, version:number) => {
  return request.delete<any,any>(API.delete_role + `?id=${id}&version=${version}`)
}
// 根据roleId查询绑定菜单
export const reqGetMenuByRoleid = (roleId: number) => {
  return request.get<any,any>(API.getMenuByRoleid + `?roleId=${roleId}`)
}
// 根据当前登录用户账户查询绑定菜单
export const reqGetMenuByUserName = (username: string) => {
  return request.get<any,any>(API.getMenuByUserName + `?username=${username}`)
}
